<template>
  <div>
    <a-modal v-model="visible" title="日志" :width="900" centered :footer="false" destroyOnClose class="return-modal">
      <s-table size="default" :rowKey="record => record.id" :columns="columns" :data="loadData" :bordered="false">
        <span slot="status" slot-scope="text">{{ text | orderStatus }}</span>
      </s-table>
    </a-modal>
  </div>
</template>
<script>
import { STable } from '../../components'
import { queryForBoxDetailLog } from '@/api/box/order'
import '@/views/box/util/filter'
import globalData from '@/views/box/util/global'
const columns = [
  {
    title: '时间',
    align: 'center',
    dataIndex: 'actionTime'
  },
  {
    title: '行为',
    align: 'center',
    dataIndex: 'memo'
  },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' }
  },
  {
    title: '操作人',
    align: 'center',
    dataIndex: 'username'
  }
]
export default {
  components: {
    STable
  },
  data() {
    this.columns = columns
    return {
      visible: false,
      data: [],
      boxId: '',
      loadData: parameter => this.fetchData(parameter)
    }
  },
  filters: {
    orderStatus(v) {
      let status = globalData.orderStatus
      let result = status.filter(e => e.stateValue == v)
      if (result.length > 0) {
        return result[0].stateName
      } else {
        return v
      }
    }
  },
  methods: {
    show(id) {
      this.boxId = id
      this.visible = true
    },
    fetchData(parameter) {
      let params = {
        page: parameter,
        requestData: {
          boxId: this.boxId
        }
      }
      return queryForBoxDetailLog(params).then(res => {
        if (res.code == 0) {
          return res
        } else {
          this.$message.warning(res.msg)
          const data = {
            page: {
              pageNo: 0,
              count: 0,
              pageSize: 10
            },
            data: []
          }
          return data
        }
      })
    }
  }
}
</script>

<style src="../less/modal.less" lang="less" scoped></style>
